<?php declare(strict_types=1);

namespace think\msg\msg;

use think\msg\BuilderTrait;

class RichTextMsg implements Msg
{
    use BuilderTrait;

    /**
     * @var string 标题
     */
    protected $title;

    protected $content = [
        [
            'tag' => 'text',
            'text' => '',
        ],
        [
            'type' => 'at',
            'user_id' => 'xxx',
        ],
        [
            'tag' => 'a',
            'url' => 'https://www.qq.com',
            'text' => '百度一下',
        ],
        [
            'tag' => 'img',
            'img_key' => 'img_7rjPQq7',
            'alt' => '图片名称',
        ],
    ];

    public function getTitle(): string
    {
        return $this->title;
    }

    public function getContent(): array
    {
        return $this->content;
    }

    public function setTitle(string $title): self
    {
        $this->title = $title;
        return $this;
    }

    /**
     * 文本内容格式 ['text' => 'xxx', 'url' => 'xxx']
     * 有 url 时为超链接
     * @param array $content 文本内容
     * @return void
     */
    public function setContent(array $content): self
    {
        $this->content = $content;
        return $this;
    }

    public function jsonSerialize(): string
    {
        return serialize($this);
    }
}
